
/**
 * AppleIIGo
 * Saturn RAM Board class
 * (C) 2007-2008 by Marc S. Ressl (mressl@umich.edu)
 * Released under the GPL
 */

#include "SaturnRAMBoard.h"

SaturnRAMBoard::SaturnRAMBoard(Motherboard * motherboard,
							   char * slotDeviceName) :
LanguageCard(motherboard, slotDeviceName) {
	ramMemoryByteNum = SATURNRAMBOARD_BYTENUM;
}

void SaturnRAMBoard::onResetAsserted(bool isRestart) {
	LanguageCard::onResetAsserted(isRestart);
	
	if (!isRestart)
		return;
	
	bankSelect = 0;
}

void SaturnRAMBoard::writeIo(UINT16 address, UINT8 value) {
	if (address & 0x4) {
		bankSelect = ((address & 0x8) >> 1) | (address & 0x3);
		setMemoryOffset();
	} else
		LanguageCard::writeIo(address, value);
}

UINT8 SaturnRAMBoard::readIo(UINT16 address) {
	if (address & 0x4) {
		bankSelect = ((address & 0x8) >> 1) | (address & 0x3);
		setMemoryOffset();
	} else
		return LanguageCard::readIo(address);
	
	return timingGenerator->readFloatingBus();
}

void SaturnRAMBoard::setMemoryOffset() {
	mmu->setLanguageCardMemory(ramMemoryOffset +
							   bankSelect * SATURNRAMBOARD_BANK_BYTENUM);
}
